package widetype_annotation;

import java.lang.annotation.*;
import java.lang.reflect.Field;

public class Test12 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
        Class<?> c1 = Class.forName("widetype_annotation.Student2");
        Annotation[] annotations = c1.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation);

        }
        TableKuang tableKuang = (TableKuang)c1.getAnnotation(TableKuang.class);
        String value = tableKuang.value();
        System.out.println(value);

        Field name = c1.getDeclaredField("name");
        FieldKuang annotation = name.getAnnotation(FieldKuang.class);
        System.out.println(annotation.col());
        System.out.println(annotation.type());
        System.out.println(annotation.length());
    }
}

@TableKuang("db_student")
class Student2{
    @FieldKuang(col = "db_id",type = "int",length = 10)
    private int id;
    @FieldKuang(col = "db_age",type = "int",length = 3)
    private int age;
    @FieldKuang(col = "db_name",type = "varchar",length = 10)
    private String name;

    @Override
    public String toString() {
        return "Student2{" +
                "id=" + id +
                ", age=" + age +
                ", name='" + name + '\'' +
                '}';
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Student2() {

    }

    public Student2(int id, int age, String name) {

        this.id = id;
        this.age = age;
        this.name = name;
    }
}


@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@interface TableKuang {
    String value();

}
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@interface FieldKuang{

    String col();

    String type();

    int length();
}